class Heap:
    def __init__(self, items):
        self.items = items

    def heapify(self, index):
        raise Exception("interface")

    def getValue(self, index):
        raise Exception("interface")

    def build(self):
        tail = self.parent(self.size - 1)
        while tail >= 0:
            self.heapify(tail)
            tail -= 1


    def left(self, index):
        return 2 * index + 1

    def right(self, index):
        return 2 * index + 2

    def parent(self, index):
        return (index - 1) // 2

    def swap(self, adx, bdx):
        aNode = self.items[adx]
        bNode = self.items[bdx]
        tmp = aNode
        self.items[adx] = bNode
        self.items[bdx] = tmp

    def pop(self):
        tail = len(self.items) - 1
        if tail < 0:
            return None
        self.swap(0, tail)
        item = self.items.pop()
        self.heapify(0)
        return item

    @property
    def next(self):
        return len(self.items) > 0

    @property
    def size(self):
        return len(self.items)